package org.fintool.runners;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;

import org.fintool.beans.Scrip;
import org.fintool.beans.StockInfoMaster;
import org.fintool.beans.Tick;
import org.fintool.common.MathUtil;
import org.fintool.common.StockMasterUtil;
import org.fintool.functional.FinanceUtilDay;

/**
 * @author pirate
 *If a stock opens positive what is the max gain it would give
 */
public class FindASXPattern {

	static int  minimumMove=0;
	static int  gainNeeded=10;



	public static void main(String[] args) {

		System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.16 Safari/534.24");







		FinanceUtilDay fd=new FinanceUtilDay();


		int countScripNetPostiveOpens;
		int countScripResonableGain;

		int countScripNetNegativeOpens;
		int countScripResonableLoss;



		String currString=null;


		try{

			//fd.updateQuotes("XJO","INDEXASX");

			Scrip scrip=fd.getScripData("XJO","INDEXASX");
			ArrayList tickerList=scrip.getTickers();

			Tick currentTicker=null;

			Tick nextTicker=null;

			countScripNetPostiveOpens=0;
			 countScripResonableGain=0;

			 countScripNetNegativeOpens=0;
			 countScripResonableLoss=0;

			//Current ticker /per ticker
				for(int tickCount=0;tickCount<tickerList.size();tickCount++ ){
					currentTicker=(Tick)tickerList.get(tickCount);



					if(tickCount<tickerList.size()-1){

					nextTicker=(Tick)tickerList.get(tickCount+1);

					System.out.println(currentTicker.getOpen()+","+currentTicker.getClose()+"|"+nextTicker.getOpen()+","+nextTicker.getClose());
					if(currentTicker.getOpen()>nextTicker.getClose()){

						countScripNetPostiveOpens+=1;
						if((currentTicker.getHigh()-currentTicker.getOpen())>=gainNeeded){
						     countScripResonableGain+=1;
						}


					}

					if(currentTicker.getOpen()<nextTicker.getClose()){

						countScripNetNegativeOpens+=1;
						if((currentTicker.getOpen()-currentTicker.getLow())>=gainNeeded){
						     countScripResonableLoss+=1;
						}


					}

					}



				}//Current ticker /per ticker

				currString=scrip.getName()+" - Total positive Gains : "+countScripNetPostiveOpens+" coverted Gain : "+
				countScripResonableGain
				+", Total Negative Opens : "+countScripNetNegativeOpens
				+" coverted Loss :"+countScripResonableLoss
				+" -%age-"
				+MathUtil.getPortion(countScripResonableGain, countScripNetPostiveOpens)
				+"/"
				+MathUtil.getPortion(countScripResonableLoss, countScripNetNegativeOpens);

				System.out.println(currString);





	     }

	    catch (Exception e) {
		e.printStackTrace();
		// TODO: handle exception
	 }

	}

}
